package com.goddess.yeecolor.base;

import android.content.Intent;
import android.content.pm.PackageManager;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;

import com.goddess.yeecolor.tools.Constans;

/**
 * Created by yeecolor on 17/1/3.
 */
public abstract class BaseFragment extends Fragment{


    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
    }

    /**
     * 点击事件
     */
    public abstract void initOnClck();


    /**
     * 初始化
     */
    public  abstract void initFindView();

    /**
     * 初始化数据
     */
    public abstract void initData();
    public boolean hasPermissin(String...permissions){

        for (String permission:permissions){
            /**
             * 判断权限  检查权限
             */
            if (ContextCompat.checkSelfPermission(getActivity(),permission)!= PackageManager.PERMISSION_GRANTED){

                return false;
            }

        }
        return true;
    }

    /**
     * 权限请求
     * @param code
     * @param permissions
     */
    public void requestPermission(int code,String...permissions){
        ActivityCompat.requestPermissions(getActivity(),permissions,code);
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        switch (requestCode){
            case Constans.WRIGTE_CALL_EXTERNAL_CODE:
                doCall();
                break;
        }
    }

    /**
     * 权限处理
     */
    public  void doCall(){

    }



}
